import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
//导入登录页面组件
import UserLogin from '@/views/UserLogin'
import UserRegister from '@/views/UserRegister'
//导入商品详情组件
import GoodDetail from '@/views/GoodDetail'
//导入用户商品列表组件
import UserGoods from '@/views/UserGoods'
//导入订单组件
import OrderListUser from '@/views/OrderListUser'
import OrderNavigation from '@/views/OrderNavigation'
import UserOrder from "@/views/UserOrder";
//导入用户全部地址组件
import UserAllAddress from '@/views/UserAllAddress'
//导入用户新增、修改地址组件
import ChangeAddress from '@/views/ChangeAddress'
//导入底部导航栏组件
import Footer from '@/views/Footer'
//导入用户首页组件
import HomePage from '@/views/HomePage'
//导入用户个人中心组件
import UserCenter from '@/views/UserCenter'
import UserCollect from "../views/UserCollect";
//导入生成订单的订单页面
import NewOrder from '@/views/NewOrder'
//导入购买成功页面
import BuySuccess from '@/views/BuySuccess'
//导入订单详情页面
import OrderDetail from '@/views/OrderDetail'
//导入商家商品页面
import MerchantGood from '@/views/MerchantGood'
Vue.use(Router)
export default new Router({
  routes: [
    {
      path: '/HelloWorld',
      name: 'HelloWorld',
      component: HelloWorld,
      meta: {
        requireAuth: false
      }
    },
    //收藏列表
    {
      path: '/UserCollect',
      name: 'UserCollect',
      component: UserCollect,
      meta: {
        requireAuth: true
      }
    },
    //添加用户登录页面路由
    {
      path:'/',
      name: 'UserLogin',
      component:UserLogin,
      meta: {
        requireAuth: false
      }
    },

    //添加用户注册页面路由
    {
      path:'/UserRegister',
      name: 'UserRegister',
      component:UserRegister,
      meta: {
        requireAuth: false
      }
    },
    //添加用户个人中心路由
    {
      path:'/UserCenter',
      name: 'UserCenter',
      component:UserCenter,
      meta: {
        requireAuth: true
      }
    },
    //添加用户商品列表路由UserGoods
    {
      path: '/UserGoods',
      name: 'UserGoods',
      component:UserGoods,
      meta: {
        requireAuth: true
      },
    },
    //添加用户订单列表路由
    {
      path: '/OrderListUser',
      name: 'OrderListUser',
      component:OrderListUser,
      meta: {
        requireAuth: true
      }
    },
    //用户订单搜索栏
    {
      path: '/OrderNavigation',
      name: 'OrderNavigation',
      component:OrderNavigation,
      meta: {
        requireAuth: true
      },
      children:[{
        path: 'UserOrder',
        component:UserOrder,
      },
      ]
    },
    //添加用户全部收货地址路由
    {
      path: '/UserAllAddress',
      name: 'UserAllAddress',
      component: UserAllAddress,
      meta: {
        requireAuth: true
      }
    },
    //添加修改和新增收货地址的路由
    {
      path: '/ChangeAddress',
      name: 'ChangeAddress',
      component: ChangeAddress,
      meta:{
        requireAuth: true
      }
    },
    //添加商品详情组件GoodDetail
    {
      path: '/GoodDetail',
      name: 'GoodDetail',
      component: GoodDetail,
      meta:{
        requireAuth: true
      }
    },
    //添加用户首页组件HomePage
    {
      path: '/HomePage',
      name: '/HomePage',
      component: HomePage,
      meta:{
        requireAuth: true
      }
    },//NewOrder
    //添加点击购买生成订单组件NewOrder
    {
      path: '/NewOrder',
      name: '/NewOrder',
      component: NewOrder,
      meta:{
        requireAuth: true
      }
    },
    //添加购买成功组件
    {
      path: '/BuySuccess',
      name: 'BuySuccess',
      component: BuySuccess,
      meta:{
        requireAuth: true
      }
    },
    //添加订单详情组件
    {
      path: '/OrderDetail',
      name: 'OrderDetail',
      component: OrderDetail,
      meta:{
        requireAuth: true
      }
    },
    //添加商家商品组件
    {
      path: '/MerchantGood',
      name: 'MerchantGood',
      component:MerchantGood,
      meta:{
        requireAuth: true
      }
    }
  ],
})

//解决VUE路由跳转出现Redirected when going from "/xxx" to "/yyy" via a navigation guard.报错
/*Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}*/

